<template>
  <div v-if="!terminalStore.terminals.length" class="text-center">
    <UFOIcon class="mx-auto h-12 w-12 text-gray-400"/>
    <h3 class="mt-2 text-sm font-medium text-gray-900">{{ $t('record.empty') }}</h3>
    <p class="mt-1 text-sm text-gray-500">{{ $t('record.empty_tip') }}</p>
    
  </div>

  <ul v-else role="list" class="divide-y divide-gray-200 text-gray-500">
    <li v-for="terminal in terminalStore.terminals" class="py-4">
      <div class="flex items-center space-x-4">
        <div class="flex-shrink-0 h-10 w-10 rounded-full text-center leading-10 ring-1 ring-gray-200">
          <BaseIcon pclass="h-5 w-5 text-gray-500 inline-block" name="DevicePhoneMobileIcon" />
        </div>
        <div class="flex-1 min-w-0">
          <p class="text-sm font-medium text-gray-900">{{ terminal.serial_num }}</p>
          <p class="text-xs text-gray-500">{{ dayjs.unix(terminal.latest_chat).format('YYYY-MM-DD HH:mm:ss') }}</p>
        </div>
        <div>
          <a 
            href="javascript:void(0)" 
            class="inline-flex items-center shadow-sm px-2.5 py-0.5 border border-gray-300 text-sm leading-5 font-medium rounded-full bg-white hover:bg-gray-50"
            @click="recordStore.fetchItems({serial_num: terminal.serial_num})"
          > 
            {{ $t('record.title') }}
          </a>
        </div>
      </div>
    </li>
    
  </ul>

</template>
<script setup>
import { ref } from 'vue'
import dayjs from 'dayjs'
// pinia
import { useTerminalStore } from '@/stores/terminal'
import { useRecordStore } from '@/stores/record'
// 模板
import UFOIcon from '@/components/icons/empty/UFOIcon.vue'

const terminalStore = useTerminalStore()
const recordStore = useRecordStore()
// 设备列表
const isFetchTerminals = ref(false)
async function getTerminals() {
  isFetchTerminals.value = true

  await terminalStore.fetchItems()

  isFetchTerminals.value = false
}
getTerminals()

</script>
